package DataStructure.array;

import java.util.Arrays;

public class Solution {

    public static int removeDuplicates(int[] nums) {
        int res = 0;

        for(int i=1; i<nums.length; i++){
            if(nums[i]!=nums[i-1]){
                res++;
                nums[res] = nums[i];
            }
        }
        System.out.println(Arrays.toString(nums));
        return res+1;
    }


    public static int removeDuplicates2(int[] nums) {
        int res = 0;
        int m = 2;

        for(int i=2; i<nums.length; i++){
            if(nums[i]==nums[i-1] && nums[i-2]==nums[i-1]){

            }else{
                nums[m] = nums[i];
                m++;
                res++;
            }
        }
        System.out.println(Arrays.toString(nums));
        return res+2;
    }

    public static void main(String[] args) {
//        int i = removeDuplicates(new int[]{1, 1, 2});
//        System.out.println("nums length: "+i);

        int i2 = removeDuplicates2(new int[]{1,1,1,2,2,3});
        System.out.println("nums length: "+i2);
    }

}
